package com.rc.myapplication.adapter;

import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.rc.myapplication.R;

public class ImageAdapter extends BaseAdapter
{
    // 定义Context
    private Context   mContext;

    public ImageAdapter(Context c)
    {
        mContext = c;
    }
    // 获取图片的个数
    public int getCount()
    {
        return 10;
    }
    // 获取图片在库中的位置
    public Object getItem(int position)
    {
        return position;
    }
    // 获取图片ID
    public long getItemId(int position)
    {
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View view= LayoutInflater.from(mContext).inflate(R.layout.grid_item,null);

        ImageView imageView;
        if (convertView == null)
        {
            // 给ImageView设置资源
            imageView = new ImageView(mContext);
            // 设置布局 图片120×120显示
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            // 设置显示比例类型
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        }
        else
        {
//            imageView = (ImageView) convertView;
        }

        return view;
    }
}
